package util
{
	//分数
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Sprite;
	import flash.geom.Point;
	
	import flash3.framework.Map;
	
	public class ImageNumber extends Sprite
	{
		private var isShowSign:Boolean = true;
		public var bitmapData:Array;
		public static var map:Map = null;
		private var distanceX:Number = 0;
		private var align:String = "left";
		private var gridWidth:Number;
		private var gridHeight:Number;
		private var centerPos:Point;
		public function ImageNumber(bmp:BitmapData)
		{
			super();
			bitmapData = HeptaFishCovert.divideBitmapData(bmp.clone(), 16, 1);
			gridWidth = bitmapData[0].width;
			gridHeight = bitmapData[0].height;
			if(!map)
			{
				map = new Map();
				map.put("0", 0);map.put("1", 1);map.put("2", 2);
				map.put("3", 3);map.put("4", 4);map.put("5", 5);
				map.put("6", 6);map.put("7", 7);map.put("8", 8);
				map.put("9", 9);map.put("+", 10);map.put("-", 11);
				map.put("*", 12);map.put("/", 13);map.put(".", 14);
				map.put(":", 15);
			}
		}
		public function set signVisible(v:Boolean):void
		{
			isShowSign = v;
		}
		public function set value(v:*):void
		{
			clear();
			var v1:String = v as String ? v : getMask(v);
			var w:Number = gridWidth * v1.length;
			var startX:Number = getStartX(v1);
			for(var i:uint = 0; i < v1.length; i++)
			{
				var index:uint = map.getValue(v1.charAt(i));
				var bitmap:Bitmap = getBitmap(index);
				bitmap.x = startX + i * gridWidth + (i==0 ? 0 :distanceX);
				addChild(bitmap);
			}
		}
		private function getStartX(v:String):Number
		{
			var length:Number = v.length;
			var w:Number = gridWidth * v.length;
			return -(w / 2);
		}
		public function getMask(v:Number):String
		{
			var v1:String = v.toString();
			
			if(isShowSign && v > 0)
			{
				return ("+" + v1);
			}
			
			return v1;
		}
		public function getBitmap(index:uint):Bitmap
		{
			var bitmap:Bitmap = new Bitmap(bitmapData[index] as BitmapData);
			return bitmap;
		}
		public function clear():void
		{
			while(this.numChildren > 0)
			{
				this.removeChildAt(0);
			}
		}
	}
}